import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		token: uni.getStorageSync('token') || '',
		userInfo: uni.getStorageSync('userInfo') || {}
	},
	getters: {
		userInfo: state => state.userInfo,
		token: state => state.token
	},
	mutations: {
		SET_USERINFO(state, userInfo) {
			state.userInfo = userInfo
			state.token = userInfo.token
			uni.setStorageSync('userInfo', userInfo || {})
			uni.setStorageSync('token', userInfo.token || '')
		}
	},
	actions: {

	}
})

export default store
